/// Main Form ///

using System.Windows.Forms;
using System.Drawing;
using System.Net;
using System.Threading;
using System;

namespace Xyne
{
	public class MainForm : Form
	{
		private MainPanel main;
		private SettingsPanel settings;
		private ManageDecksPanel manageDecks;
		private EditDeckPanel editDeck;
		private SinglePlayerPanel singleplayer;
		
		public MainForm()
		{ 
			Text = "Xyne";
			FormBorderStyle = FormBorderStyle.FixedDialog;
			
			main = new MainPanel();
			main.Exit.Click += new EventHandler(ExitClicked);
			main.Settings.Click += new EventHandler(SettingsClicked);
			main.Deck.Click += new EventHandler(DeckClicked);
			main.SinglePlayer.Click += new EventHandler(SinglePlayerClicked);
			this.Controls.Add(main);
			
			singleplayer = new SinglePlayerPanel();
			singleplayer.Visible = false;
			singleplayer.BackCallback = new SinglePlayerPanel.ButtonClicked(SinglePlayerDone);
			this.Controls.Add(singleplayer);
			
			settings = new SettingsPanel();
			settings.Visible = false;
			settings.Callback = new SettingsPanel.ButtonClicked(SettingsDone);
			this.Controls.Add(settings);
			
			manageDecks = new ManageDecksPanel();
			manageDecks.Visible = false;
			manageDecks.BackCallback = new ManageDecksPanel.ButtonClicked(ManageDecksDone);
			manageDecks.EditCallback = new ManageDecksPanel.EditDeck(EditDeck);
			this.Controls.Add(manageDecks);
			
			editDeck = new EditDeckPanel();
			editDeck.Visible = false;
			editDeck.BackCallback = new EditDeckPanel.ButtonClicked(EditDone);
			this.Controls.Add(editDeck);
			
			Size = main.Size;
		}
		
		private void ExitClicked(object sender, EventArgs e)
		{
			Application.Exit();
		}
		
		private void SinglePlayerClicked(object sender, EventArgs e)
		{
			main.Visible = false;
			singleplayer.Visible = true;
			
			SetSize(singleplayer.Size);
		}
		
		private void SinglePlayerDone()
		{
			main.Visible = true;
			singleplayer.Visible = false;
			
			SetSize(main.Size);
		}
		
		private void SettingsClicked(object sender, EventArgs e)
		{
			main.Visible = false;
			settings.Visible = true;
			
			SetSize(settings.Size);
		}
		
		private void DeckClicked(object sender, EventArgs e)
		{
			main.Visible = false;
			manageDecks.Visible = true;
			
			SetSize(manageDecks.Size);
		}
		
		private void SettingsDone()
		{
			main.Visible = true;
			settings.Visible = false;
			
			SetSize(main.Size);
		}
		
		private void EditDeck(string filename)
		{
			editDeck.LoadDeck(filename);
			
			editDeck.Visible = true;
			manageDecks.Visible = false;
			
			SetSize(editDeck.Size);
		}
		
		private void EditDone()
		{
			editDeck.Visible = false;
			manageDecks.Visible = true;
			
			SetSize(manageDecks.Size);
		}
		
		private void ManageDecksDone()
		{
			main.Visible = true;
			manageDecks.Visible = false;
			
			SetSize(main.Size);
		}
		
		private void SetSize(Size size)
		{
			Size = size;
			
			CenterToScreen();
		}
	}
}